/**
 * 
 */
package de.cbf.cam.dsa.model.entities;

import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.CollectionOfElements;

import de.cbf.cam.dsa.model.Activator;
import de.cbf.cam.dsa.model.entities.states.stateChanger.StateChangerBase;
import de.cbf.cam.dsa.model.persistence.Header;

/**
 * @author Nebelritter
 *
 */
@Entity
public class OneWound extends Header{
	
	public static final String woundFinal="Final"; 
	
	/**
	 * @uml.property  name="zone"
	 */
	protected String zone;
	/**
	 * @uml.property  name="finalWound"
	 */
	protected boolean finalWound;
	
	/**
	 * @uml.property  name="stateChangersWoundBattle"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.entities.states.stateChanger.StateChangerBase"
	 */
	protected List<StateChangerBase> stateChangersWoundBattle = new ArrayList<StateChangerBase>();
	/**
	 * @uml.property  name="stateChangersHealBattle"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="de.cbf.cam.dsa.model.entities.states.stateChanger.StateChangerBase"
	 */
	protected List<StateChangerBase> stateChangersHealBattle = new ArrayList<StateChangerBase>();
	/**
	 * @uml.property  name="parameters"
	 * @uml.associationEnd  qualifier="parameter:java.lang.String java.lang.Integer"
	 */
	protected HashMap<String, Integer> parameters = new HashMap<String, Integer>();
	
	public static String PROPERTYNAME= "OneWound:";
	/**
	 * @uml.property  name="propertyChangeSupport"
	 */
	public PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
//========================
//		constructors
//========================
	
	public OneWound(String zone) {
		super();	
		this.zone=zone;
	}	
	@Override
	public String toString() {
		String description ="";
		description+= zone;
		if(finalWound){
			description+= "(final)";
		}
		return description;
	}
	
	public List<String> getPossibleParameters(){
		List<String> possibleParameters = new ArrayList<String>();
		possibleParameters.addAll(parameters.keySet());
		return possibleParameters;
	}
	
	public void setParameter(String parameter,Integer value){
		if(parameters.containsKey(parameter)){
			parameters.put(parameter, value);
		}else{
			Activator.logger.error("Woundparameter: "+parameter+" not accepted for Wound: "+this);
		}		
	}
//========================
//	   public methods
//========================

	@ManyToMany(cascade=CascadeType.ALL)
	public List<StateChangerBase> getWoundEffects(){
		return stateChangersWoundBattle;
	}
	@ManyToMany(cascade=CascadeType.ALL)
	public List<StateChangerBase> getHealEffects(){
		return stateChangersHealBattle;
	}
	
	public void setWoundEffects(List<StateChangerBase> woundEffects){
		stateChangersWoundBattle = woundEffects;
	}
	
	public void setHealEffects(List<StateChangerBase> healEffects){
		stateChangersHealBattle = healEffects;
	}
	
	/**
	 * @return
	 * @uml.property  name="zone"
	 */
	public String getZone() {
		return zone;
	}

	/**
	 * @param position
	 * @uml.property  name="zone"
	 */
	public void setZone(String position) {
		this.zone = position;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"zone", null, position);
	}

	public void addStateChangerWound(StateChangerBase stateChangerBase) {
		stateChangersWoundBattle.add(stateChangerBase);
		
	}
	public void addStateChangerHeal(StateChangerBase stateChangerBase) {
		stateChangersHealBattle.add(stateChangerBase);		
	}
//========================
//    standard methods
//========================

//========================
//		getters / setters
//========================
	/**
	 * @return  the finalWound
	 * @uml.property  name="finalWound"
	 */
	public boolean isFinalWound() {
		return finalWound;
	}

	/**
	 * @param finalWound  the finalWound to set
	 * @uml.property  name="finalWound"
	 */
	public void setFinalWound(boolean finalWound) {
		this.finalWound = finalWound;
	}

	@Override
	@Id
	public String getGuid() {
		return guid;
	}

	@Override
	public void setGuid(String guid) {
		this.guid=guid;
	}
	
	@CollectionOfElements
	public HashMap<String, Integer> getParameters() {
		return parameters;
	}
	public void setParameters(HashMap<String, Integer> parameters) {
		this.parameters = parameters;
	}

	

//========================
// 	   private methods
//========================

//========================
// 	SHORT property access
//========================


//========================
//		
//========================

//========================
//		listeners
//========================

}
